package com.usoft.thrift.example.contact.client;

import java.util.Calendar;
import java.util.List;

import com.usoft.thrift.example.Contact;
import com.usoft.thrift.example.ContactService;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

public class ThriftClient {

    public static void main(String[] args) throws Exception {
        TTransport transport = new TSocket("localhost", 8111);
        TProtocol protocol = new TCompactProtocol(transport);

//        ContactService.Client client = new ContactService.Client.Factory()
//            .getClient(protocol);

        ContactService.Client client = new ContactService.Client(protocol);
        transport.open();
        List<Contact> list = client.getAll();
        System.out.println(list);
        client.save(
            new Contact(1, "zhangpu", Calendar.getInstance().getTimeInMillis(),
                "1389612222", "192.168.2.1", null));
        client.save(
            new Contact(1, "zhangpu", Calendar.getInstance().getTimeInMillis(),
                "1389612222", "192.168.2.1", null));
        client.save(
            new Contact(1, "zhangpu", Calendar.getInstance().getTimeInMillis(),
                "1389612222", "192.168.2.1", null));
        client.remove(1);
        transport.close();
    }
}
